package com.real.RealPlayerTest;

import android.test.ActivityInstrumentationTestCase2;
import android.util.Log;

import com.jayway.android.robotium.solo.Solo;

@SuppressWarnings("unchecked")
public class TestAPK extends ActivityInstrumentationTestCase2 {
	private static final String TARGET_PACKAGE_ID = "com.real.RealPlayer"; //CHANGE
	private static final String LAUNCHER_ACTIVITY_FULL_CLASSNAME = "com.real.RealPlayer.Home"; //CHANGE
	private static Class launcherActivityClass;
	static {
		try {
			launcherActivityClass = Class.forName(LAUNCHER_ACTIVITY_FULL_CLASSNAME);
		} catch (ClassNotFoundException e) {
			throw new RuntimeException(e);
		}
	}

	public TestAPK() throws ClassNotFoundException {
		super(TARGET_PACKAGE_ID, launcherActivityClass);
	}

	private Solo solo;

	@Override
	protected void setUp() throws Exception {
		solo = new Solo(getInstrumentation(), getActivity());
	}
	
	public void testPlaySongWMA() {
		solo.clickOnButton("Songs");	//select topic songs
		solo.clickOnButton(1);	//select song 1 wma
		solo.sleep(5000);
		solo.clickOnButton(1);	//pause
		solo.sleep(1000);
	}
	
	public void testPlaySongMP3() {
		solo.clickOnButton("Songs");	//select topic songs
		solo.clickOnButton(1);	//select song 2 mp3
		solo.sleep(5000);
		solo.clickOnButton(1);	//pause
		solo.sleep(1000);
	}
	
	public void testNextSong() {
		solo.clickOnButton("Songs");
		solo.clickOnButton(1);	//selected song
		solo.sleep(5000);		
		solo.clickOnButton(3);	//next song
		solo.sleep(5000);
		solo.clickOnButton(1);	//pause
		solo.sleep(1000);
	}
	
	public void testVideoPlayback() {
		solo.clickOnButton("Videos");
		//solo.clickOnButton("All Videos");
		solo.clickInList(0);
		solo.sleep(5000);	//play for 5sec
		solo.sleep(1000);
	}
	
	public void testImageSlideshow() {		
		solo.clickOnButton("Photos");
		solo.sleep(2000);
		solo.clickOnImage(0);	//first picture
		solo.sleep(3000);
		solo.clickOnMenuItem("Slide Show");	//slideshow start
		solo.sleep(15000);	//play for 10sec slideshow
		solo.sleep(1000);
	}
	
	public void testPlaySongMP3WithHeadsetPlugIn() {
		Log.d(getName(), "Please Plug in the Headset");
		solo.sleep(5000); // plug in headset
		solo.clickOnButton("Songs");	//select topic songs
		solo.clickOnButton(1);	//select song 2 mp3
		solo.sleep(5000);
		solo.clickOnButton(1);	//pause
		solo.sleep(1000);
	}
	
	
//	public void testPlaylistCreate() {	//todo not available - strange
//		String playlist = "TestPlaylist";
//		String items = "Sum 41";
//		solo.clickOnButton("Playlists");
//		solo.clickOnButton("Add to Playlist");
//		solo.clickOnButton(items);	//todo
//		solo.clickOnButton("Create new playlist");
//		solo.enterText(null, playlist);
//		assertTrue(solo.searchText(playlist));
//		solo.clickOnButton(playlist);		
//		solo.sleep(3000);
//	}


	@Override
	public void tearDown() throws Exception {
		solo.finishOpenedActivities();
	}
}